<template>
	<view class="evaluate app-pages">
		<view class="textarea">
			<u--textarea v-model="value" height="380rpx" count placeholder="请输入评价内容" maxlength="200">
			</u--textarea>
		</view>

		<view class="upload-image">
			<view class="" style="margin: 20rpx 0;">上传图片</view>
			<u-upload :fileList="fileList1"
			 	width="220rpx"
			 	height="220rpx"
				:divNumb="2"
			 @afterRead="afterRead" @delete="deletePic" name="1" multiple :maxCount="10">
			</u-upload>
		</view>
		
		<view class="button">
			<view class="submit" @click="handleRouter('/myPages/evaluate/success')">提交</view>
		</view>
	</view>
</template>
<script>
	export default {
		name: 'evaluate',
		data() {
			return {
				value: '',
				fileList1: []
			}
		},
		methods: {
			handleRouter(url) {
				uni.navigateTo({
					url
				})
			},
			// 删除图片
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			async afterRead(event) {
				// 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					}))
					fileListLen++
				}
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					resolve(url)
					// let a = uni.uploadFile({
					// 	url: 'http://192.168.2.21:7001/upload', // 仅为示例，非真实的接口地址
					// 	filePath: url,
					// 	name: 'file',
					// 	formData: {
					// 		user: 'test'
					// 	},
					// 	success: (res) => {
					// 		setTimeout(() => {
					// 			resolve(res.data.data)
					// 		}, 1000)
					// 	}
					// });
				})
			},
		},
	}
</script>
<style lang="scss" scoped>
	::v-deep .u-upload__wrap{
		justify-content: space-between;
	}
	::v-deep .u-upload__success{
		border-bottom-color: #f74062 !important;
		border-right-color: #f74062 !important;
	}
	::v-deep .u-upload__wrap__preview{
		margin: 0 0 16rpx 0 !important;
	}
	::v-deep .u-upload__button{
		margin: 0 0 16rpx 0 !important;
	}
	.evaluate {
		padding-bottom: 100rpx;
		.button {
			box-sizing: border-box;
			padding-top: 80rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			.submit {
				width: 240rpx;
				height: 60rpx;
				line-height: 60rpx;
				text-align: center;
				border: 2rpx solid #f74062;
				border-radius: 10rpx;
				color: #f74062;
			}
		}
		.textarea{
			margin: 30rpx 0;
		}
		.upload-image{
			margin-top: 30rpx;
		}
	}
</style>
